export default function ajax(url = '', params = {}, type = 'GET', header = {
		'content-type': 'application/x-www-form-urlencoded'
					}, flag) {
	// {headers:{'Content-Type':'application/json;charset=utf8'}}
	return new Promise((resolve, reject) => {
		// uni.showLoading({
		// 	title: '加载中',
		// 	mask: true,
		// })
		// 模拟测试请求头
		// uni.setStorageSync('token','123');
		
		// 请求头里带一个token
		// const token =  uni.getStorageSync('token');
		
		// if(token) {
		// 	header.accessToken = token;
		// }
		uni.request({
			method: type,
			url: url,
			data: params, 
			dataType: "jsonp", //数据格式设置为jsonp
			jsonp: "callback",
			header: header,
		}).then((response) => {
			// setTimeout(function() {
			// 	uni.hideLoading();
			// }, 200);
			let [error, res] = response;
			resolve(JSON.parse(res.data));
		}).catch(error => {
			let [err, res] = error;
			reject(err)
		})
	});
}